package com.fifth.home.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.BottomArticle;
import com.fifth.home.service.IBottomArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第五组
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/home/bottomArticle")
@Api(tags = "底部文章相关接口")
public class BottomArticleController {
    @Autowired
    private IBottomArticleService bottomArticleService;

    /**
     * 后台查询底部文章
     */
    @ApiOperation(value = "后台底部文章初始化页面查询接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", dataType = "int"),
                    @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int"),
            }
    )
    @PostMapping("getAllBottomArticle/{currentPage}/{pageSize}")
    public CommonResult getAllBottomArticle(@PathVariable Integer currentPage, @PathVariable Integer pageSize){
        return bottomArticleService.selectAllBottomArticle(currentPage,pageSize);
    }

    /**
     * 后台模糊查询底部文章
     */
    @ApiOperation(value = "后台底部文章模糊查询接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", dataType = "int"),
                    @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int"),
                    @ApiImplicitParam(name = "bottomArticle", value = "底部文章实体类", dataType = "BottomArticle")
            }
    )
    @PostMapping("getAllfurryBottomArticle/{currentPage}/{pageSize}")
    public CommonResult getAllBottomArticle(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody BottomArticle bottomArticle){
        return bottomArticleService.selectAllfurryBottomArticle(currentPage,pageSize,bottomArticle);
    }

    /**
     * 后台添加
     * @param bottomArticle
     * @return
     */
    @ApiOperation(value = "后台底部文章添加接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "bottomArticle", value = "底部文章实体类", dataType = "BottomArticle")
            }
    )
    @PostMapping("addBottomArticle")
    public CommonResult addBottomArticle(@RequestBody BottomArticle bottomArticle){
        return bottomArticleService.insertBottomArticle(bottomArticle);
    }

    /**
     * 修改底部文章状态
     *
     * @param id
     * @param isDisable
     * @return
     */
    @ApiOperation("底部文章修改状态接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "底部文章id属性", dataType = "String"),
                    @ApiImplicitParam(name = "isDisable", value = "底部文章状态 0正常 1禁用", dataType = "String")
            }
    )
    @PostMapping("changeStatus/{id}/{isDisable}")
    public CommonResult updateDisable(@PathVariable String id, @PathVariable String isDisable) {
        return bottomArticleService.updateStatus(id, isDisable);
    }


    /**
     * 删除底部文章  逻辑删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "底部文章删除接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "id属性", dataType = "String")
            }
    )
    @PostMapping("deleteBottomArticle/{id}")
    public CommonResult deleteBottomArticle(@PathVariable String id) {
        return bottomArticleService.removeBottomArticle(id);
    }

    /**
     * 修改底部文章标题
     *
     * @param bottomArticle
     * @return
     */
    @ApiOperation(value = "底部文章修改标题接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "bottomArticle", value = "底部文章实体类", dataType = "bottomArticle")
            }
    )
    @PostMapping("editBottomArticle")
    public CommonResult editBottomArticle(@RequestBody BottomArticle bottomArticle){
        return bottomArticleService.updateBottomArticle(bottomArticle);
    }


    /**
     * 查看所有底部文章(前端调用)
     */
    @ApiOperation(value = "底部文章查询接口(前端调用)")
    @PostMapping("getQianAllBottomArticle")
    public CommonResult getQianAllBottomArticle(){
        return bottomArticleService.selectQianBottomArticle();
    }

}
